﻿using Anke.SHManage.Model;
using Anke.SHManage.MSSQLDAL;
using Anke.SHManage.Utility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Anke.SHManage.BLL
{
    public partial class C_OilCardRechargeBLL : BaseBLL<C_OilCardRecharge>
    {
        private C_OilCardRechargeDAL dal = new C_OilCardRechargeDAL();

        //查询油卡列表
        public object GetRechargeList(int page, int rows, string start, string end, string center, string station, string cardCode,
                                     string invoiceNumber, E_StatisticsPermisson em, string selfWorkCode, string selfCenterID, string selfStationID)
        {
            return dal.GetRechargeList(page, rows, start, end, center, station, cardCode, invoiceNumber, em, selfWorkCode, selfCenterID, selfStationID);
        }
        //取C_OilCardRecharge表中id最大的一条数据
        public List<C_OilCardRecharge> GetMaxID()
        {
            string sql = @" select * from C_OilCardRecharge where id in (select max(id) from C_OilCardRecharge)";
            return base.DALContext.IC_OilCardRechargeDAL.ExcuteSqlToList(sql);
        }
        //通过油卡卡号取绑定人工号
        public string GetWorkID(string cardCode)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@"
            select DriverWorkID from C_OilCardInfo where CardCode = '" + cardCode + @"' 
                    ");
            object ds = SqlHelper.ExecuteScalar(SqlHelper.MainConnectionString, CommandType.Text, sb.ToString(), null);

            return ds.ToString();
        }
        //通过油卡卡号取绑定人姓名
        public string GetName(string cardCode)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@"
            select DriverName from C_OilCardInfo where CardCode = '" + cardCode + @"' 
                    ");
            object ds = SqlHelper.ExecuteScalar(SqlHelper.MainConnectionString, CommandType.Text, sb.ToString(), null);

            return ds.ToString();
        }
        //通过油卡卡号取所属分中心编码
        public string GetCenterID(string cardCode)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@"
            select CenterID from C_OilCardInfo where CardCode = '" + cardCode + @"' and  IsActive = 1
                    ");
            object ds = SqlHelper.ExecuteScalar(SqlHelper.MainConnectionString, CommandType.Text, sb.ToString(), null);

            return ds.ToString();
        }
        //通过油卡卡号取所属分站编码
        public string GetStationID(string cardCode)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@"
            select StationID from C_OilCardInfo where CardCode = '" + cardCode + @"'  and  IsActive = 1
                    ");
            object ds = SqlHelper.ExecuteScalar(SqlHelper.MainConnectionString, CommandType.Text, sb.ToString(), null);

            return ds.ToString();
        }
        //根据卡号查对应司机工号，姓名，分中心，分站，卡内金额
        public C_OilCardLink GetOilCardLinkList(string cardCode)
        {
            return dal.GetOilCardLinkList(cardCode);
        }
        public C_OilCardInfo GetOilCardList(string cardCode)
        {
            return dal.GetOilCardList(cardCode);
        }
        //根据id取出原来的加油记录数据
        public C_OilCardRefuel GetOldModel(int id)
        {
            return dal.GetOldModel(id);
        }
        //根据id取出原来的充值记录数据
        public C_OilCardRecharge GetOldRechargeModel(int id)
        {
            return dal.GetOldRechargeModel(id);
        }
    }
}
